package mo.offer_special;

import mo.common.ListNode;

public class L021 {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode slow = dummy;
        while (n > 0) {
            slow = slow.next;
            n--;
        }
        ListNode copy = dummy;
        while (slow.next != null) {
            dummy = dummy.next;
            slow = slow.next;
        }

        dummy.next = dummy.next.next;
        return copy.next;
    }

}
